package com.ruoyi.coal.modules.coalpile.utils.compute;

import cn.hutool.core.util.NumberUtil;
import com.ruoyi.coal.modules.coalpile.domain.vo.CoalPileInfoVo;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

public class Compute {
    public static Map<String, Double> computeWholeCoalpile(String coalYardName, List<CoalPileInfoVo> pdfVo1) {
        Double sumVolume = Double.valueOf(0.0D);
        Double sumWeight = Double.valueOf(0.0D);
        HashMap<String, Double> stringDoubleHashMap = new HashMap<>();
        if (pdfVo1.size() == 1) {
            sumVolume = Optional.<Double>ofNullable(((CoalPileInfoVo)pdfVo1.get(0)).getVolume()).orElse(Double.valueOf(0.0D));
            sumWeight = Optional.<Double>ofNullable(((CoalPileInfoVo)pdfVo1.get(0)).getWeight()).orElse(Double.valueOf(0.0D));
        } else {
            for (int i = pdfVo1.size() - 1; i >= 0; i--) {
                if (!((CoalPileInfoVo)pdfVo1.get(i)).getName().equals(coalYardName)) {
                    sumVolume = Double.valueOf(sumVolume.doubleValue() + ((Double)Optional.<Double>ofNullable(((CoalPileInfoVo)pdfVo1.get(i)).getVolume()).orElse(Double.valueOf(0.0D))).doubleValue());
                    sumWeight = Double.valueOf(sumWeight.doubleValue() + ((Double)Optional.<Double>ofNullable(((CoalPileInfoVo)pdfVo1.get(i)).getWeight()).orElse(Double.valueOf(0.0D))).doubleValue());
                }
            }
        }
        stringDoubleHashMap.put("sumVolume", Double.valueOf(Double.parseDouble(NumberUtil.roundStr(sumVolume.doubleValue(), 3))));
        stringDoubleHashMap.put("sumWeight", Double.valueOf(Double.parseDouble(NumberUtil.roundStr(sumWeight.doubleValue(), 3))));
        return stringDoubleHashMap;
    }
}

